package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ChainGoodsService;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsAddVO;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsEditVO;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsListVO;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsTransformVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/chain/goods")
public class ChainGoodsController extends BaseController{
	
	@Autowired
	private ChainGoodsService chainGoodsService; 
	
	@ApiOperation(value = "添加商品")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(ChainGoodsAddVO chainGoodsAddVO) {
		return chainGoodsService.add(chainGoodsAddVO);
	}
	
	@ApiOperation(value = "编辑商品")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO edit(ChainGoodsEditVO chainGoodsEditVO) {
		AssertUtil.notBlank(chainGoodsEditVO.getId(), "id is required.");
		return chainGoodsService.edit(chainGoodsEditVO);
	}
	
	@ApiOperation(value = "查询所有商品")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findPageAll(DataTablesParamVO dtp, ChainGoodsListVO chainGoodsListVO) {
		return chainGoodsService.findPageAll(dtp, chainGoodsListVO);
	}
	
	@ApiOperation(value = "查询商品")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		return chainGoodsService.findById(id);
	}
	
	@ApiOperation(value = "查询商品(关联信息)")
	@RequestMapping(value = "/other/{id}", method = RequestMethod.GET)
	public ResultVO findByIdForOther(@PathVariable String id) {
		return chainGoodsService.findByIdForOther(id);
	}
	
	@ApiOperation(value="商户模拟删除")
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public ResultVO delete(@PathVariable String id){
		return chainGoodsService.delete(id);
	}
	
	@ApiOperation(value = "批量更新状态")
	@RequestMapping(value = "batch/status", method = RequestMethod.PUT)
	public ResultVO batchUpdateStatus(String[] ids, Integer status,String sessionId) {
		return chainGoodsService.batchUpdateStatus(ids, status,sessionId);
	}

	
	@ApiOperation(value = "更新状态/上架/下架/申请在审核")
	@RequestMapping(value = "status", method = RequestMethod.PUT)
	public ResultVO updateStatus(String id, Integer status,String sessionId) {
		return chainGoodsService.updateStatus(id, status,sessionId);
	}
	
	
	@ApiOperation(value="查询连锁品牌商户商品")
	@RequestMapping(value="/id",method=RequestMethod.GET) 
	public Map<String, Object> findByChainId(DataTablesParamVO dtp,ChainGoodsListVO chainGoodsListVO){
		return chainGoodsService.findByChainId(dtp, chainGoodsListVO);
	}
	
	@ApiOperation(value="导入连锁品牌商品")
	@RequestMapping(value="/import",method=RequestMethod.POST)
	public ResultVO importChainGoods(ChainGoodsTransformVO chainGoodsTransformVO){
		return chainGoodsService.importChainGoods(chainGoodsTransformVO);
	}
	
	@ApiOperation(value = "审核通过或拒绝(总部商品审核)")
	@RequestMapping(value = "edit/status", method = RequestMethod.PUT)
	public ResultVO editStatus(ChainGoodsEditVO chainGoodsEditVO) {
		return chainGoodsService.editStatus(chainGoodsEditVO);
	}
	
	@ApiOperation(value = "批量审核通过或拒绝(总部商品审核)")
	@RequestMapping(value = "batch/edit/status", method = RequestMethod.PUT)
	public ResultVO batchEditStatus(String[] ids, Integer status,String auditFailDescription) {
		return chainGoodsService.batchEditStatus(ids, status,auditFailDescription);
	}
	
	@ApiOperation(value = "总部强制下架商铺商品")
	@RequestMapping(value = "/shop/change", method = RequestMethod.PUT)
	public ResultVO updateGoodsStatus(String id,String auditFailDescription) {
		return chainGoodsService.updateGoodsStatus(id,auditFailDescription);
	}
	
	@ApiOperation(value="批量导入连锁品牌商品")
	@RequestMapping(value="batch/import",method = RequestMethod.PUT)
	public ResultVO batchImportChainGoods(String[] ids,String sessionId){
		return chainGoodsService.batchImportChainGoods(ids,sessionId);
	}
}
